package edu.whut.mall.portal.controller;

import edu.whut.mall.common.api.CommonResult;
import edu.whut.mall.portal.service.IGroupBuyOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * @author Wayne
 * @projectName d9lab-mall
 * @description: 团购订单管理器
 * @date 2020/11/9 16:02
 */
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/groupBuyOrder")
@RestController
@Api(value="团购订单管理器",tags = {"团购订单管理器"})
public class RestGroupBuyOrderController {

    private final IGroupBuyOrderService groupBuyOrderService;


    @ApiOperation("根据订单状态来获取订单详情")
    @PostMapping(value = "/getGroupBuyOrderVoByOrderStatus")
    public CommonResult getGroupBuyOrderVoByOrderStatus(@RequestParam(value="pageNum",defaultValue = "1") Integer pageNum,
                                                        @RequestParam(value="size",defaultValue ="10") Integer size,
                                                        @NotNull @RequestParam Long userId,
                                                        @RequestParam(required = false)Integer orderStatus){
        return CommonResult.success(groupBuyOrderService.getGroupBuyOrderVoByOrderStatus(pageNum, size, userId, orderStatus));
    }


    @ApiOperation("根据recordId和userId来获取订单详情")
    @PostMapping(value = "/getGroupBuyOrderVoByRecordIdAndUserId")
    public CommonResult getGroupBuyOrderVoByRecordIdAndUserId(@NotNull @RequestParam Long recordId,
                                                              @NotNull @RequestParam Long userId){
        return CommonResult.success(groupBuyOrderService.getGroupBuyOrderVoByRecordIdAndUserId(recordId, userId));
    }

    @ApiOperation("根据orderNo来获取订单详情")
    @PostMapping(value = "/getGroupBuyOrderVoByOrderNo")
    public CommonResult getGroupBuyOrderVoByOrderNo(@NotNull @RequestParam String orderNo){
        return CommonResult.success(groupBuyOrderService.getGroupBuyOrderVoByOrderNo(orderNo));
    }

    @ApiOperation("确认收货")
    @PostMapping(value = "/confirmReceipt")
    public CommonResult confirmReceipt(@NotNull @RequestParam String orderNo){
        return CommonResult.success(groupBuyOrderService.confirmReceipt(orderNo));
    }

    @ApiOperation("删除订单")
    @PostMapping(value = "/deleteOrder")
    public CommonResult deleteOrder(@NotNull @RequestParam String orderNo){
        return CommonResult.success(groupBuyOrderService.deleteOrder(orderNo));
    }
}
